Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dont call spawn cb more than once on error #243

Merged
merged 12 commits into from
May 17, 2018

Conversation

dryajov
Copy link
Member

@dryajov dryajov commented May 9, 2018

No description provided.

@ghost ghost assigned dryajov May 9, 2018
@ghost ghost added the status/in-progress In progress label May 9, 2018
vasco-santos
vasco-santos previously approved these changes May 10, 2018
fsdiogo
fsdiogo previously approved these changes May 10, 2018
@vasco-santos
Copy link
Member

As a new release occurred today, could you fix the introduced merge conflict @dryajov ?

@dryajov dryajov dismissed stale reviews from fsdiogo and vasco-santos via e0fc124 May 14, 2018 17:46
@dryajov
Copy link
Member Author

dryajov commented May 14, 2018

@vasco-santos done - conflicts resolved.

@@ -160,7 +161,6 @@ describe('Spawn options', function () {
})
})

// TODO ?? What is this test trying to prove?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tries to spawn a node an then manually attach an ipfs-api to it - we do that in some places in ipfs-api tests and others...

@@ -72,6 +72,8 @@ class Node extends EventEmitter {
libp2p: this.opts.libp2p
})

// TODO: should this be wrapped in a process.nextTick(), for context:
// https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/#why-use-process-nexttick
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not do it now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asking for feedback there mostly - did you take a look at the link?

], (err) => {
node.removeListener('error', errHandler)
if (!called) { callback(err, node) }
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the dependency once you also added in this PR?

@@ -92,7 +92,6 @@
"lodash.defaults": "^4.2.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update ipfs-repo to 0.20.0 and update all deps below 1.0.0 to be ~ rather then ^

@ghost ghost assigned daviddias May 14, 2018
@daviddias
Copy link
Member

Can I get a memory refresher on why the following error is currently happening?

Debug: internal, implementation, error
    AssertionError: expected [Error: invalid block] to not exist
    at f.spawn (/Users/imp/code/js-ipfsd-ctl/test/add-retrieve.spec.js:29:28)
    at Node.errHandler (/Users/imp/code/js-ipfsd-ctl/src/factory-in-proc.js:136:7)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Node.emit (events.js:211:7)
    at IPFS.Node.exec.once.err (/Users/imp/code/js-ipfsd-ctl/src/ipfsd-in-proc.js:77:41)

@daviddias
Copy link
Member

The added test is failing, both locally and on CI

      don't callback twice on error
Debug: internal, implementation, error
    TypeError: ipfsd.once is not a function
    at once.strict (/Users/imp/code/js-ipfsd-ctl/test/spawn-options.spec.js:452:17)
    at f (/Users/imp/code/js-ipfsd-ctl/node_modules/once/once.js:36:25)
    at series (/Users/imp/code/js-ipfsd-ctl/src/factory-daemon.js:144:7)
    at /Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/parallel.js:39:9
    at /Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/once.js:12:16
    at replenish (/Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/eachOfLimit.js:59:25)
    at iterateeCallback (/Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/eachOfLimit.js:49:17)
    at /Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/onlyOnce.js:12:16
    at /Users/imp/code/js-ipfsd-ctl/node_modules/async/internal/parallel.js:36:13
    at f (/Users/imp/code/js-ipfsd-ctl/node_modules/once/once.js:25:25)
    at Socket.data (/Users/imp/code/js-ipfsd-ctl/src/ipfsd-daemon.js:281:11)
    at emitOne (events.js:121:20)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at Pipe.onread (net.js:607:20)
        1) spawn with error

@daviddias
Copy link
Member

Just missing #243 (comment). @dryajov go ahead and pull the latest changes and apply the CR + fix the test. Then we will have CI green :)

@dryajov
Copy link
Member Author

dryajov commented May 14, 2018

I've reverted back to using ipfs-repo because of (from IRC):

15:19 <dryajov> daviddias: seems like we need ipfs-repo after all… 
15:19 <dryajov> here is why: we need to check if the repo exists, close/cleanup repo after we finished
15:19 <dryajov> and we need to be able to do it across node and browser...
15:20 <dryajov> thats the catch...
15:20 <dryajov> we don’t need to create it (just let ipfs take care of that), but we need it for cleanup/checking if it exists
15:21 <dryajov> we can do all that manually, but, I’m sure we’ll run into nasty corner cases...

Copy link
Member

@daviddias daviddias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ipfs-repo is definitely not required as a main dependency, nor it seems that useful for tests, in fact, it might mislead the developer to think the repo was closed properly.

package.json Outdated
@@ -86,22 +86,22 @@
"hapi": "^16.6.2",
"hat": "0.0.3",
"ipfs-api": "^21.0.0",
"ipfs-repo": "^0.19.0",
"ipfs-repo": "~0.20.0",
Copy link
Member

@daviddias daviddias May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dryajov even with #243 (comment), the teardown is just used for testing. It should not be a regular dependency nor be a util from src.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid it's not only used in tests, we use it the cleanup method as well -

this.repo.teardown(callback)


AFAIK, when calling ipfs.stop(), the repo doesn't get cleaned up, hence we need something to be able to purge it from the browsers storage (indexDB, websql, etc...), not doing that would give a false sense of the repo being cleaned up/deleted when its not, and doing it by hand would possibly lead us to deal with browser inconsistencies and other corner cases that are most likely taken care already by ipfs-repo.

I might be missing something in my assessment, would be happy to hear otherwise 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, slight correction - seems like the only place we would need ipfs-repo would be in

(cb) => node.repo._isInitialized(err => {

I'll take a closer look how to better handle that piece, once thats out it should be easy to remove ipfs-repo.

}

return repo
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also based on #243 (comment), this is an antipattern. What this is creating is that IPFS might fail to close the repo and we are forcely closing it and deleting.

The only things you should need for tests are the idb.deleteDatabase and rimraf calls

@vasco-santos
Copy link
Member

@dryajov @diasdavid can we go forward with this to have the CI green again?

@daviddias
Copy link
Member

Just missing Circle CI :)

@dryajov
Copy link
Member Author

dryajov commented May 17, 2018

Hnm. Circle looks weird, I'll take a look.

@dryajov
Copy link
Member Author

dryajov commented May 17, 2018

@diasdavid @vasco-santos can I get write perms so I can trigger rebuilds on circle and other CIs?

screen shot 2018-05-17 at 10 35 36 am

@vasco-santos
Copy link
Member

Fine by me! But I am not able to give you permissions, at least AFAIK

@dryajov
Copy link
Member Author

dryajov commented May 17, 2018

ok, circle is green.

@daviddias daviddias merged commit ca44996 into master May 17, 2018
@daviddias daviddias deleted the fix/spawn-err-callback branch May 17, 2018 18:58
@ghost ghost removed the status/in-progress In progress label May 17, 2018
@vasco-santos vasco-santos mentioned this pull request May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants